package com.oumizz.doublelistview;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.Toast;
import com.oumizz.doublelistview.adapter.GridViewAdapter;
import com.oumizz.doublelistview.adapter.LeftListViewAdapter;
import com.oumizz.doublelistview.adapter.RightListViewAdapter;


public class MainActivity extends AppCompatActivity {

    public String[] items = {"一","二","三","四","二","三","四","二","三","四","二","三","四"};

    public String[] grid_items = {"全部分类","进口产品","国产产品","新人专属","会员专享"};
    public String[] left_items = {"类别1","类别2","类别3","类别4","类别5","类别6","类别7","类别8"};
    private Context ctx;



    private  int item = 0;
    private LeftListViewAdapter leftListViewAdapter;
    private ListView mListViewLeft;
    private GridViewAdapter gridViewAdapter;
    private GridView mGridView;
    private Activity mActivity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ctx = this;
        mActivity = this;
        initView();
    }

    private void initView() {

        //左侧的listView  分类
        mListViewLeft = (ListView) findViewById(R.id.left_mListView);
        leftListViewAdapter = new LeftListViewAdapter(ctx,left_items,item);
        mListViewLeft.setAdapter(leftListViewAdapter);

        mListViewLeft.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                item = i;
                leftListViewAdapter = new LeftListViewAdapter(ctx,left_items,item);
                mListViewLeft.setAdapter(leftListViewAdapter);
                leftListViewAdapter.notifyDataSetChanged();
                
                Toast.makeText(ctx,"点击了左侧的ListView的："+i+"条目",Toast.LENGTH_SHORT).show();

                System.out.println("mListViewLeft.getChildAt(i):"+mListViewLeft.getChildAt(i));

                System.out.println("mListViewLeft.getChildCount():"+mListViewLeft.getChildCount());

            }
        });

        //右侧ListView item 的具体详情
        ListView mListViewRight = (ListView) findViewById(R.id.mListView1);
        RightListViewAdapter listAdapter = new RightListViewAdapter(ctx,items);
        mListViewRight.setAdapter(listAdapter);
        mListViewRight.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                Toast.makeText(ctx,"点击了右侧的ListView的："+i+"条目",Toast.LENGTH_SHORT).show();
            }
        });


        //右侧小分类标记
        mGridView = (GridView) findViewById(R.id.gv_brind);
        gridViewAdapter = new GridViewAdapter(ctx,grid_items,item);
        mGridView.setAdapter(gridViewAdapter);

        mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                item = i;
                gridViewAdapter = new GridViewAdapter(ctx,grid_items,item);
                mGridView.setAdapter(gridViewAdapter);
                gridViewAdapter.notifyDataSetChanged();

                Toast.makeText(ctx,"点击了右侧的grifView的："+i+"条目",Toast.LENGTH_SHORT).show();
            }
        });

    }
}
